<h4><i class="fa fa-tag"></i> <?php echo Yii::t('helpdesk','New Ticket'); ?>  <?php if(!empty($dept)): ?>&raquo; <?php echo $dept['category_name']; ?><?php endif;?></h4><hr>
<?php 
foreach(Yii::app()->user->getFlashes() as $key => $message){
	echo '<div class="'.$key.'"><p>'.$message."</p></div>\n";
}
?>
<a href="javascript:void(0);" onClick="window.history.back(-1);"><i title="go back" class="fa fa-arrow-left"></i> <?php echo Yii::t('helpdesk','Go back'); ?></a>
<form id="create-ticket" class="form-horizontal" enctype="multipart/form-data" method="post">
<table style="width:100%;" class="table table-bordered table-nonfluid table-condensed">
	<tbody>
	<tr>
		<td width="75px"><?php echo Yii::t('helpdesk','Full Name'); ?></td>
		<td><?php echo $user['user_fullname']; ?></td>
	</tr>
	<tr>
		<td><?php echo Yii::t('helpdesk','Email'); ?></td>
		<td><?php echo $user['user_email']; ?></td>
	</tr>
	<tr <?php if(!empty($dept_id)): ?>style="display:none;"<?php endif; ?>>
    	<td><?php echo Yii::t('helpdesk','Department'); ?></td>
        <td>
        	<select id="dept" name="dept[]" class="form-control" required>
            	<option value="">-- <?php echo Yii::t('helpdesk','Choose'); ?> --</option>
				<?php foreach($arrDepts as $R): ?>
                <?php if($R['category_level'] == 0): ?>
                <option  value="<?php echo $R['category_id']; ?>" <?php if(!empty($dept_id) && $dept_id == $R['category_id']): ?>selected<?php endif?>><?php echo $R['category_name']; ?></option>
                <?php endif; ?>
				<?php endforeach; ?>
            </select>
        </td>
    </tr>
    <tr>
    	<td><?php echo Yii::t('helpdesk','Subject'); ?></td>
        <td><select id="subject" name="dept[]" class="form-control"></select></td>
    </tr>
    <?php if(!isset($dept['category_name']) || 'hr' != strtolower($dept['category_name'])): ?>
	<tr>
    	<td><?php echo Yii::t('helpdesk','Urgency'); ?></td>
        <td>
        	<select name="fields[1]" class="form-control"  required="">
            	<option value="">-- <?php echo Yii::t('helpdesk','Choose'); ?> --</option>
				<option value="1"><?php echo Yii::t('helpdesk','Low'); ?></option>
				<option value="2"><?php echo Yii::t('helpdesk','Medium'); ?></option>
				<option value="3"><?php echo Yii::t('helpdesk','High'); ?></option>
			</select>
        </td>
   	</tr>
    <?php endif; ?>
    <tr>
    	<td><?php echo Yii::t('helpdesk','Title'); ?></td>
        <td>
        	<input type="text" required="" class="form-control" id="title" name="title" style="width:100%" maxlength="256">
        </td>
   	</tr>
	<tr>
		<td valign="top"><?php echo Yii::t('helpdesk','Content'); ?></td>
		<td><textarea style="width: 100%" name="body" rows="5" class="form-control" required></textarea></td>
	</tr>
    <tr>
		<td valign="top"><?php echo Yii::t('helpdesk','Attachment'); ?></td>
		<td><input type="file" name="attach" id="attach"> <small>(<?php echo Yii::t('helpdesk','Max'); ?>: <?php echo ini_get("upload_max_filesize"); ?>) <br> <?php echo Yii::t('helpdesk','If you\'d like to upload a bunch of files please combine them into one compressed file (such as zip, rar...)'); ?></small></td>
	</tr>
</tbody>
</table>

<input type="submit" class="btn btn-large btn-primary" value="<?php echo Yii::t('helpdesk','Create'); ?>">
</form>
<script type="text/javascript">
	var depts = new Array();
	<?php foreach($arrDepts as $R): ?>
	<?php if($R['category_level'] == 0): ?>depts[<?php echo $R['category_id']; ?>] = new Array();<?php else: ?>depts[<?php echo $R['category_parent']; ?>][<?php echo $R['category_id']; ?>] = "<?php echo $R['category_name']; ?>"; <?php endif; ?>
	<?php endforeach; ?>
	$(document).ready(function(){
		loadSubjects($('#create-ticket select[id=dept]').val(), '', $('#create-ticket select[id=subject]'));
		$('#create-ticket select[id=dept]').change(function(){
			loadSubjects($(this).val(), '', $('#create-ticket select[id=subject]'));
		});
	});
</script>